<!DOCTYPE html>





<html class="theme-next muse use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="generator" content="Hexo 3.9.0">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.3.0">
  <link rel="mask-icon" href="/images/logo.svg?v=7.3.0" color="#222">

<link rel="stylesheet" href="/css/main.css?v=7.3.0">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '7.3.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    save_scroll: false,
    copycode: {"enable":false,"show_result":false,"style":null},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    }
  };
</script>

  <meta property="og:type" content="website">
<meta property="og:title" content="XuQi&#39;s Blog">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="XuQi&#39;s Blog">
<meta property="og:locale" content="zh-CN">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="XuQi&#39;s Blog">
  <link rel="canonical" href="http://yoursite.com/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: true,
    isPost: false,
    isPage: false,
    isArchive: false
  };
</script>

  <title>XuQi's Blog</title>
  








  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  <div class="container sidebar-position-left">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">XuQi's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
  </ul>

    

</nav>
</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content page-home">
            
  <section id="posts" class="posts-expand">
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/20/hostapd_dhcpd/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/09/20/hostapd_dhcpd/" class="post-title-link" itemprop="url">hostapd_dhcpd</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-09-20 09:12:57" itemprop="dateCreated datePublished" datetime="2019-09-20T09:12:57+00:00">2019-09-20</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          
            <h4 id="网卡选择"><a href="#网卡选择" class="headerlink" title="网卡选择"></a>网卡选择</h4><p>不同于windows上，大部分的网卡都支持软AP ，linux下的网卡需要支持mode master的才可以做软AP 。具体识别方法如下</p>
<p>1、iwconfig识别</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">iwconfig wlxec888fbd5d61 mode master</span><br><span class="line">Error for wireless request &quot;Set Mode&quot; (8B06) :</span><br><span class="line">    SET failed on device wlxec888fbd5d61 ; Invalid argument.</span><br></pre></td></tr></table></figure>

<p>2、iw识别</p>
<p>上面的操作失败，证明不支持。再进行进一步的验证，有些新的网卡用的是mac80211 framework，对于这些网卡的话，用iwconfig来测试它是否支持master模式是行不通的。</p>
<p>因为他们是使用新的 nl80211接口在用户空间通信的。再使用iw命令进行测试：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]$ sudo  iw list</span><br><span class="line">........略........................</span><br><span class="line">	Supported interface modes:</span><br><span class="line">		 * IBSS</span><br><span class="line">		 * managed</span><br><span class="line">		 * AP</span><br><span class="line">		 * AP/VLAN</span><br><span class="line">		 * monitor</span><br><span class="line">		 * mesh point</span><br><span class="line">		 * P2P-client</span><br><span class="line">		 * P2P-GO</span><br></pre></td></tr></table></figure>

<p>如果「Supported interface modes」中有「AP」的话，那么恭喜你，你的无线网卡可以架设虚拟AP 。如果没有则不支持。</p>
<p>3、驱动识别</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">root@XuQi:~/proj/Private# ethtool -i wlxec888fbd5d61</span><br><span class="line">driver: rtl8192cu</span><br><span class="line">version: 4.15.0-60-generic</span><br><span class="line">firmware-version: N/A</span><br><span class="line">expansion-rom-version: </span><br><span class="line">bus-info: 2-6:1.0</span><br><span class="line">supports-statistics: yes</span><br><span class="line">supports-test: no</span><br><span class="line">supports-eeprom-access: no</span><br><span class="line">supports-register-dump: no</span><br><span class="line">supports-priv-flags: no</span><br></pre></td></tr></table></figure>

<p>例如上面的示例中使用的驱动为rtl8192cu，通过<a href="http://wireless.kernel.org/en/users/Drivers" target="_blank" rel="noopener">http://wireless.kernel.org/en/users/Drivers</a> AP模式支持的驱动列表里的查找AP项为yes，证明其支持。</p>
<p><img src="/2019/09/20/hostapd_dhcpd/1568948144309.png" alt="1568948144309"></p>
<p>即然如此，如何在未购买网卡前选择一款一定支持的网卡呢？wireless.kernel.org也给我们提供了一个方法 ，通过<a href="http://wireless.kernel.org/en/users/Devices" target="_blank" rel="noopener">http://wireless.kernel.org/en/users/Devices</a>  硬件列表<br>（该页按pci、usb、pcmcia接口类型做了区分，点开相应的类型即可查看具体的硬件）。当然，这个表里列出的并不完全，也并不能保证是最适合做软AP的硬件 。是否识合请参查看上面的三个方法。</p>
<h4 id="编译hostapd"><a href="#编译hostapd" class="headerlink" title="编译hostapd"></a>编译hostapd</h4><h5 id="编译依赖libnl-3-2-25"><a href="#编译依赖libnl-3-2-25" class="headerlink" title="编译依赖libnl-3.2.25"></a>编译依赖libnl-3.2.25</h5><p><a href="http://lists.infradead.org/pipermail/libnl/2014-July/001549.html" target="_blank" rel="noopener">http://lists.infradead.org/pipermail/libnl/2014-July/001549.html</a></p>
<p>下载：<a href="http://www.infradead.org/~tgr/libnl/files/libnl-3.2.25.tar.gz" target="_blank" rel="noopener">http://www.infradead.org/~tgr/libnl/files/libnl-3.2.25.tar.gz</a></p>
<h5 id="编译依赖openssl"><a href="#编译依赖openssl" class="headerlink" title="编译依赖openssl"></a>编译依赖openssl</h5><p><a href="https://www.openssl.org/source/" target="_blank" rel="noopener">https://www.openssl.org/source/</a></p>
<p>下载：<a href="https://www.openssl.org/source/openssl-1.0.2t.tar.gz" target="_blank" rel="noopener">https://www.openssl.org/source/openssl-1.0.2t.tar.gz</a></p>
<h5 id="编译hostapd-1"><a href="#编译hostapd-1" class="headerlink" title="编译hostapd"></a>编译hostapd</h5><p><a href="http://w1.fi/hostapd/" target="_blank" rel="noopener">http://w1.fi/hostapd/</a></p>
<p>下载：<a href="http://w1.fi/releases/hostapd-2.9.tar.gz" target="_blank" rel="noopener">http://w1.fi/releases/hostapd-2.9.tar.gz</a></p>
<h5 id="hostapd-rtl871xdrv补丁"><a href="#hostapd-rtl871xdrv补丁" class="headerlink" title="hostapd-rtl871xdrv补丁"></a>hostapd<em>-rtl871xdrv补丁</em></h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone http://www.github.com/pritambaral/hostapd-rtl871xdrv</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Configuration file: hostapd.conf</span><br><span class="line">drv-&gt;ifindex=4</span><br><span class="line">l2_sock_recv==l2_sock_xmit=0x0x1130410</span><br><span class="line">ioctl[SIOCSIWMODE]: Invalid argument</span><br><span class="line">Could not set interface to mode(3)!</span><br><span class="line">Could not set interface to master mode!</span><br><span class="line">rtl871xdrv driver initialization failed.</span><br><span class="line">wlxec888fbd5d61: interface state UNINITIALIZED-&gt;DISABLED</span><br><span class="line">wlxec888fbd5d61: AP-DISABLED </span><br><span class="line">wlxec888fbd5d61: CTRL-EVENT-TERMINATING </span><br><span class="line">hostapd_free_hapd_data: Interface wlxec888fbd5d61 wasn&apos;t started</span><br></pre></td></tr></table></figure>

<p><em>这个问题的出现是由于你的kernel内核没有配置对wifi的master模式的支持（即对AP热点的支持），解决这个问题的办法就是用make menuconfig打开图形界面，然后选择IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)这个选项；这个选择的地址可以参考WG217 wifi模块RTL8811CU的移植（linux）这篇博客里面的第三部分:RTL8821CU驱动所需的支持中的第2小点：master的选项所在位置有详细的讲解。</em><br><em>原文链接：<a href="https://blog.csdn.net/weixin_44362642/article/details/88891384" target="_blank" rel="noopener">https://blog.csdn.net/weixin_44362642/article/details/88891384</a></em></p>
<h4 id="编译wpa-supplicant"><a href="#编译wpa-supplicant" class="headerlink" title="编译wpa_supplicant"></a><em>编译wpa_supplicant</em></h4><p><em><a href="http://w1.fi/releases/wpa_supplicant-2.9.tar.gz" target="_blank" rel="noopener">http://w1.fi/releases/wpa_supplicant-2.9.tar.gz</a></em></p>
<p><em>添加</em></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">CFLAGS +=  -I/home/xuqi/hostadp/build/include/libnl3</span><br><span class="line">LIBS += -L/home/xuqi/hostadp/build/lib</span><br><span class="line"></span><br><span class="line">CFLAGS += -I/home/xuqi/hostadp/build/include/</span><br></pre></td></tr></table></figure>

<p><em>编译错误，注释DBUS</em></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># Add support for new DBus control interface</span><br><span class="line"># (fi.w1.hostap.wpa_supplicant1)</span><br><span class="line">#CONFIG_CTRL_IFACE_DBUS_NEW=y</span><br><span class="line"></span><br><span class="line"># Add introspection support for new DBus control interface</span><br><span class="line">#CONFIG_CTRL_IFACE_DBUS_INTRO=y</span><br></pre></td></tr></table></figure>

<h5 id="启动"><a href="#启动" class="headerlink" title="启动:"></a><em>启动:</em></h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo ./wpa_supplicant -i wlxec888fbd5d61 -c ./wpa_supplicant.conf -B</span><br></pre></td></tr></table></figure>

<h5 id="扫描："><a href="#扫描：" class="headerlink" title="扫描："></a><em>扫描：</em></h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo wpa_cli -i wlxec888fbd5d61  scan</span><br><span class="line">sudo wpa_cli -i wlxec888fbd5d61  scan_result</span><br><span class="line">sudo wpa_cli -i wlxec888fbd5d61 add_network</span><br></pre></td></tr></table></figure>

<h5 id="连接："><a href="#连接：" class="headerlink" title="连接："></a><em>连接：</em></h5><p><em>如果要连接加密方式是<code>[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]</code> (<code>wpa</code>加密)，<code>wifi</code>名称是<code>name</code>，<code>wifi</code>密码是：<code>psk</code>。</em></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo wpa_cli -i wlxec888fbd5d61 set_network 0 ssid &apos;&quot;dev-xu&quot;&apos;</span><br><span class="line">sudo wpa_cli -i wlxec888fbd5d61 set_network 0 psk &apos;&quot;xuqi9999&quot;&apos;</span><br><span class="line">sudo wpa_cli -i wlxec888fbd5d61 enable_network 0</span><br></pre></td></tr></table></figure>

<h5 id="保存连接："><a href="#保存连接：" class="headerlink" title="保存连接："></a><em>保存连接：</em></h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo wpa_cli -i wlxec888fbd5d61 save_config</span><br></pre></td></tr></table></figure>

<h5 id="断开连接："><a href="#断开连接：" class="headerlink" title="断开连接："></a><em>断开连接：</em></h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo wpa_cli -i wlxec888fbd5d61 disable_network 0</span><br></pre></td></tr></table></figure>

<h5 id="分配IP"><a href="#分配IP" class="headerlink" title="分配IP:"></a><em>分配IP:</em></h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">udhcpc -i wlxec888fbd5d61 -s /etc/udhcpc.script -q</span><br></pre></td></tr></table></figure>

<h3 id="Soft-blocking"><a href="#Soft-blocking" class="headerlink" title="Soft-blocking"></a><em>Soft-blocking</em></h3><p><em>输出到<code>sudo rfkill list</code>显示您的网卡是”soft-blocked”。</em></p>
<p><em>当无线卡通过内核发信号通知switch-off时，可能会发生这种情况。</em></p>
<p><em>请尝试以下步骤：</em></p>
<ol>
<li><em>在终端中运行：<code>sudo rfkill unblock wifi; sudo rfkill unblock all</code></em></li>
<li><em>重新运行<code>sudo rfkill list</code>以确认该卡已被解除阻止。</em></li>
<li><em>重启</em></li>
<li><em>再次重新运行<code>sudo rfkill list</code>以确认已保留的解除阻塞。</em></li>
<li><em>重新运行<code>sudo lshw -class network</code> – 您现在应该看到内核已识别(或不识别)无线卡。</em></li>
</ol>
<p><em>如果已识别无线内核模块(不应该说”unclaimed”)，则网络管理器现在应该能够看到您的空闲区域中可用的无线网络。</em></p>

          
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/17/c++基础知识总结/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/09/17/c++基础知识总结/" class="post-title-link" itemprop="url">c++基础知识总结</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-09-17 12:32:40" itemprop="dateCreated datePublished" datetime="2019-09-17T12:32:40+00:00">2019-09-17</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          
            <h3 id="C-基础知识"><a href="#C-基础知识" class="headerlink" title="C++基础知识"></a>C++基础知识</h3><h4 id="指针和引用的区别"><a href="#指针和引用的区别" class="headerlink" title="指针和引用的区别"></a>指针和引用的区别</h4><ul>
<li>是否分配空间</li>
<li>是否需要初始化</li>
<li>是否支持多级</li>
<li>是否可以支持++</li>
<li>sizeof的大小</li>
<li>引用是直接访问变量，指针是间接访问</li>
<li>指针需要做类型检查</li>
<li>引用底层是通过指针实现的</li>
<li>作为参数时，引用是传地址，指针实质上是传地址</li>
</ul>
<h4 id="从汇编层去解释一下引用"><a href="#从汇编层去解释一下引用" class="headerlink" title="从汇编层去解释一下引用"></a>从汇编层去解释一下引用</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1.	9:          int x = 1;</span><br><span class="line">2.	00401048    mov         dword ptr [ebp-4],1</span><br><span class="line">3.	10:         int &amp;b = x;</span><br><span class="line">4.	0040104F    lea         eax,[ebp-4]</span><br><span class="line">5.	00401052    mov         dword ptr [ebp-8],eax</span><br></pre></td></tr></table></figure>

<p>lea eax,[ebp-4]  这条语句将x的地址ebp-4放入eax寄存器mov dword ptr [ebp-8],eax 这条语句将eax的值放入b的地址ebp-8中,作用即：将x的地址存入变量b中,所以从汇编层次来看，的确引用是通过指针来实现的。</p>
<h4 id="指针参数传递和引用参数传递"><a href="#指针参数传递和引用参数传递" class="headerlink" title="指针参数传递和引用参数传递"></a>指针参数传递和引用参数传递</h4><ul>
<li>指针传参，实质上是值传递，被调函数的形参会被当做局部变量，在栈中开辟空间，不会影响主调函数的实参。</li>
<li>引用参数,形参也开辟了空间，但存放的是主调函数实参变量的地址。被调函数的对行参操作，实际上是间接寻址。</li>
<li>从编译角度，程序编译的时候，分别将指针和引用添加到了符号表上，符号表记入了变量名和变量所对应的地址。指针变量在符号表对应的地址值，为指针变量的地址，所以可以改变。而引用在符号表对应地址值为引用对象的地址。符号表生成后就不能再改变，所以引用的对象不能修改。</li>
</ul>
<h4 id="形参和实参的区别"><a href="#形参和实参的区别" class="headerlink" title="形参和实参的区别"></a>形参和实参的区别</h4><ul>
<li>分配内存的生命周期</li>
<li></li>
</ul>
<h4 id="static的用法和作用"><a href="#static的用法和作用" class="headerlink" title="static的用法和作用"></a>static的用法和作用</h4><h4 id="静态变量什么时候初始化"><a href="#静态变量什么时候初始化" class="headerlink" title="静态变量什么时候初始化"></a>静态变量什么时候初始化</h4>
          
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/08/22/Telematics-Box/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/08/22/Telematics-Box/" class="post-title-link" itemprop="url">Telematics-Box</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-08-22 12:00:52" itemprop="dateCreated datePublished" datetime="2019-08-22T12:00:52+00:00">2019-08-22</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          
            <h3 id="功能"><a href="#功能" class="headerlink" title="功能"></a>功能</h3><table>
<thead>
<tr>
<th>个人免提通话</th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>Telematics常规服务呼叫(Advisor   Call)</td>
<td></td>
</tr>
<tr>
<td>位置服务</td>
<td></td>
</tr>
<tr>
<td>时钟功能</td>
<td></td>
</tr>
<tr>
<td>安全功能:</td>
<td>a.    按键触发紧急呼叫      b.  碰撞告警通知(气囊爆破通知ACN/预碰撞通知AACN)      c.  防盗通知(VTD/CTD)      d.  车辆追踪      e.  电子围栏</td>
</tr>
<tr>
<td>远程控制</td>
<td>a.    远程上锁/解锁      b.  远程闪灯/鸣笛      c.  远程启动      d.  远程启动抑制      e.  远程车速限制</td>
</tr>
<tr>
<td>车辆远程诊断:</td>
<td></td>
</tr>
<tr>
<td>车辆数据监控:</td>
<td>a.    数据采集上传      b.  车辆数据记录</td>
</tr>
<tr>
<td>远程目的地设置</td>
<td></td>
</tr>
<tr>
<td>TBT导航</td>
<td></td>
</tr>
<tr>
<td>远程刷新</td>
<td>a.        本模块刷新       b.        车内他模块刷新</td>
</tr>
<tr>
<td>数据通道</td>
<td>a.        以太网公共无线接入数据路由      b.       WIFI热点(b,g,n)</td>
</tr>
<tr>
<td>灵活功能配置能力</td>
<td></td>
</tr>
<tr>
<td>自诊断</td>
<td></td>
</tr>
<tr>
<td>测试工具功能</td>
<td></td>
</tr>
<tr>
<td>虚拟顾问</td>
<td></td>
</tr>
</tbody></table>

          
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/08/20/GPS基础知识/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/08/20/GPS基础知识/" class="post-title-link" itemprop="url">GPS基础知识</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-08-20 23:09:37" itemprop="dateCreated datePublished" datetime="2019-08-20T23:09:37+00:00">2019-08-20</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          
            
          
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/08/14/Linux管道pipe/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/08/14/Linux管道pipe/" class="post-title-link" itemprop="url">Linux管道pipe</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-08-14 22:06:55" itemprop="dateCreated datePublished" datetime="2019-08-14T22:06:55+00:00">2019-08-14</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          
            <h2 id="Linux进程间通信之管道"><a href="#Linux进程间通信之管道" class="headerlink" title="Linux进程间通信之管道"></a>Linux进程间通信之管道</h2><h3 id="什么是管道？"><a href="#什么是管道？" class="headerlink" title="什么是管道？"></a>什么是管道？</h3><p>管道是一种最基本的IPC机制，作用于有血缘关系的进程之间，完成数据传递。调用pipe系统函数即可创建一个管道。</p>
<ol>
<li><p>其本质是一个伪文件(实为内核缓冲区)</p>
</li>
<li><p>由两个文件描述符引用，一个表示读端，一个表示写端。</p>
</li>
<li><p>规定数据从管道的写端流入管道，从读端流出。</p>
</li>
</ol>
<p><strong>管道的原理:</strong> </p>
<p>管道实为内核使用环形队列机制，借助内核缓冲区(4k)实现。</p>
<p>例如: </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -ef | grep init</span><br></pre></td></tr></table></figure>

<p><strong>管道的局限性：</strong></p>
<p>① 数据自己读不能自己写。</p>
<p>② 数据一旦被读走，便不在管道中存在，不可反复读取。</p>
<p>③ 由于管道采用半双工通信方式。因此，数据只能在一个方向上流动。</p>
<p>④ <strong>只能在有公共祖先的进程间使用管道。</strong></p>
<h4 id="pipe调用"><a href="#pipe调用" class="headerlink" title="pipe调用"></a>pipe调用</h4><h5 id="创建管道"><a href="#创建管道" class="headerlink" title="创建管道"></a>创建管道</h5><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">pipe</span><span class="params">(<span class="keyword">int</span> pipefd[<span class="number">2</span>])</span></span>; 成功：<span class="number">0</span>；失败：<span class="number">-1</span>，设置errno</span><br></pre></td></tr></table></figure>

<p>函数调用成功返回r/w两个文件描述符。无需open，但需手动close。规定：fd[0] → r； fd[1] → w，就像0对应标准输入，1对应标准输出一样。向管道文件读写数据其实是在读写内核缓冲区。</p>
<p>管道创建成功以后，创建该管道的进程（父进程）同时掌握着管道的读端和写端。如何实现父子进程间通信呢？通常可以采用如下步骤：</p>
<p><img src="/2019/08/14/Linux管道pipe/image-20190814221735897.png" alt="image-20190814221735897"></p>
<h5 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h5><ol>
<li>父进程调用pipe函数创建管道，得到两个文件描述符fd[0]、fd[1]指向管道的读端和写端。</li>
<li>父进程调用fork创建子进程，那么子进程也有两个文件描述符指向同一管道。</li>
<li>父进程关闭管道读端，子进程关闭管道写端。父进程可以向管道中写入数据，子进程将管道中的数据读出。由于管道是利用环形队列实现的，数据从写端流入管道，从读端流出，这样就实现了进程间通信。</li>
</ol>
<h5 id="管道的读写行为"><a href="#管道的读写行为" class="headerlink" title="管道的读写行为"></a>管道的读写行为</h5><p>使用管道需要注意以下4种特殊情况（<strong>假设都是阻塞I/O操作</strong>，没有设置O_NONBLOCK标志）：</p>
<ol>
<li><p>如果所有指向管道<strong>写端的文件描述符都关闭了</strong>（管道写端引用计数为0），而仍然有进程从管道的读端读数据，那么管道中剩余的数据都被读取后，再次read会返回0，就像读到文件末尾一样。</p>
</li>
<li><p>如果有指向管道<strong>写端的文件描述符没关闭</strong>（管道写端引用计数大于0），而持有管道写端的进程也没有向管道中写数据，这时有进程从管道读端读数据，那么管道中剩余的数据都被读取后，再次read会阻塞，直到管道中有数据可读了才读取数据并返回。</p>
</li>
<li><p>如果所有指向管道<strong>读端的文件描述符都关闭了</strong>（管道读端引用计数为0），这时有进程向管道的写端write，那么该进程会收到信号SIGPIPE，<strong>通常会导致进程异常终止</strong>。当然也可以对SIGPIPE信号实施捕捉，不终止进程。具体方法信号章节详细介绍。</p>
</li>
<li><p>如果有指向管道<strong>读端的文件描述符没关闭</strong>（管道读端引用计数大于0），而持有管道读端的进程也没有从管道中读数据，这时有进程向管道写端写数据，那么在管道被写满时再次write会阻塞，直到管道中有空位置了才写入数据并返回。</p>
</li>
</ol>
<h5 id="总结："><a href="#总结：" class="headerlink" title="总结："></a>总结：</h5><p>① 读管道：</p>
<ol>
<li>管道中有数据，read返回实际读到的字节数。</li>
</ol>
<ol start="2">
<li><p>管道中无数据：</p>
<p>(1) 管道写端被全部关闭，read返回0 (好像读到文件结尾)</p>
<p>(2) 写端没有全部被关闭，read阻塞等待(不久的将来可能有数据递达，此时会让出cpu)</p>
</li>
</ol>
<p>② 写管道：</p>
<ol>
<li>管道读端全部被关闭， 进程异常终止(也可使用捕捉SIGPIPE信号，使进程不终止)</li>
</ol>
<ol start="2">
<li><p>管道读端没有全部关闭：</p>
<p>(1) 管道已满，write阻塞。</p>
<p>(2) 管道未满，write将数据写入，并返回实际写入的字节数。</p>
</li>
</ol>

          
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/08/03/树莓派交叉编译/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/08/03/树莓派交叉编译/" class="post-title-link" itemprop="url">树莓派交叉编译</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-08-03 14:56:40" itemprop="dateCreated datePublished" datetime="2019-08-03T14:56:40+00:00">2019-08-03</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          
            <h3 id="挂载共享smb"><a href="#挂载共享smb" class="headerlink" title="挂载共享smb"></a>挂载共享smb</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install cifs-utils </span><br><span class="line">sudo mount -t cifs //ip/文件夹 /mnt/文件夹 -o username=用户名,password=密码,vers=1.0</span><br><span class="line"></span><br><span class="line">sudo mount -t cifs //192.168.1.100/93ee/software /mnt/</span><br></pre></td></tr></table></figure>

<h3 id="Ubuntu-上配置树莓派的交叉编译环境envbuild-sh"><a href="#Ubuntu-上配置树莓派的交叉编译环境envbuild-sh" class="headerlink" title="Ubuntu 上配置树莓派的交叉编译环境envbuild.sh"></a>Ubuntu 上配置树莓派的交叉编译环境<strong>envbuild.sh</strong></h3><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/bin/bash</span></span><br><span class="line">mkdir -p ~/toolchain</span><br><span class="line">cd ~</span><br><span class="line"><span class="keyword">if</span> [ <span class="variable">$1</span> == <span class="string">"pi"</span> ]; then</span><br><span class="line">	url=<span class="string">"https://s3.amazonaws.com/RTI/Community/ports/toolchains/raspbian-toolchain-gcc-4.7.2-linux32.tar.gz"</span></span><br><span class="line">	name=<span class="string">"$(pwd)/toolchain/raspbian-toolchain-gcc-4.7.2-linux32"</span></span><br><span class="line">		</span><br><span class="line">	<span class="keyword">if</span> [ ! -d <span class="string">"<span class="variable">$name</span>"</span> ]; then</span><br><span class="line">		wget <span class="variable">$url</span></span><br><span class="line">		tar -zxvf raspbian-toolchain-gcc-<span class="number">4.7</span>.<span class="number">2</span>-linux32.tar.gz <span class="variable">$name</span></span><br><span class="line">	fi</span><br><span class="line">	export PATH=<span class="variable">$name</span>/bin:<span class="variable">$PATH</span></span><br><span class="line">	export CROSS_COMPILE=arm-raspbian-linux-gnueabi-</span><br><span class="line">	export ARCH=arm</span><br><span class="line">	</span><br><span class="line">fi</span><br><span class="line">cd -</span><br></pre></td></tr></table></figure>

<p><strong>使用方法：</strong></p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">. envbuild.sh pi</span><br></pre></td></tr></table></figure>

<h4 id="Ubuntu编译QT"><a href="#Ubuntu编译QT" class="headerlink" title="Ubuntu编译QT"></a>Ubuntu编译QT</h4><p><a href="https://blog.csdn.net/christine14122/article/details/83621585" target="_blank" rel="noopener">https://blog.csdn.net/christine14122/article/details/83621585</a></p>
<p><strong>编辑脚本</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">!/bin/bash</span></span><br><span class="line"> ./configure \</span><br><span class="line"> -prefix ../qt-output \</span><br><span class="line"> -xplatform linux-g++-64 \</span><br><span class="line"> -no-static \</span><br><span class="line"> -qt-libpng \</span><br><span class="line"> -qt-libjpeg \</span><br><span class="line"> -qt-zlib \</span><br><span class="line"> -no-strip \</span><br><span class="line"> -no-framework \</span><br><span class="line"> -no-sse2 \</span><br><span class="line"> -no-sse3 \</span><br><span class="line"> -no-sse4.1 \</span><br><span class="line"> -no-sse4.2 \</span><br><span class="line"> -no-avx \</span><br><span class="line"> -no-avx2 \</span><br><span class="line"> -no-avx512 \</span><br><span class="line"> -no-mips_dsp \</span><br><span class="line"> -no-mips_dspr2 \</span><br><span class="line"> -no-icu \</span><br><span class="line"> -no-sql-sqlite \</span><br><span class="line"> -no-accessibility \</span><br><span class="line"> -no-ssl \</span><br><span class="line"> -disable-system-proxies \</span><br><span class="line"> -no-cups \</span><br><span class="line"> -no-gtk \</span><br><span class="line"> -no-opengles3 \</span><br><span class="line"> -no-xcb \</span><br><span class="line"> -no-ico \</span><br><span class="line"> -no-opengl \</span><br><span class="line"> -no-eglfs \</span><br><span class="line"> -no-direct2d \</span><br><span class="line"> -no-directfb \</span><br><span class="line"> -no-gbm \</span><br><span class="line"> -no-kms \</span><br><span class="line"> -no-mirclient \</span><br><span class="line"> -no-xcb \</span><br><span class="line"> -no-xkbcommon-evdev \</span><br><span class="line"> -no-xkbcommon-x11 \</span><br><span class="line"> -no-doubleconversion \</span><br><span class="line"> -enable-linuxfb \</span><br><span class="line"> -qt-freetype \</span><br><span class="line"> -make libs \</span><br><span class="line"> -nomake examples \</span><br><span class="line"> -nomake tests \</span><br><span class="line"> -nomake tools \</span><br><span class="line"> -opensource \</span><br><span class="line"> -confirm-license \</span><br><span class="line"> -skip qt3d \</span><br><span class="line"> -skip qtactiveqt \</span><br><span class="line"> -skip qtandroidextras \</span><br><span class="line"> -skip qtcanvas3d \</span><br><span class="line"> -skip qtcharts \</span><br><span class="line"> -skip qtconnectivity \</span><br><span class="line"> -skip qtdatavis3d \</span><br><span class="line"> -skip qtdeclarative \</span><br><span class="line"> -skip qtdoc \</span><br><span class="line"> -skip qtgamepad \</span><br><span class="line"> -skip qtgraphicaleffects \</span><br><span class="line"> -skip qtlocation \</span><br><span class="line"> -skip qtmacextras \</span><br><span class="line"> -skip qtmultimedia \</span><br><span class="line"> -skip qtnetworkauth \</span><br><span class="line"> -skip qtpurchasing \</span><br><span class="line"> -skip qtquickcontrols \</span><br><span class="line"> -skip qtquickcontrols2 \</span><br><span class="line"> -skip qtremoteobjects \</span><br><span class="line"> -skip qtscript \</span><br><span class="line"> -skip qtscxml \</span><br><span class="line"> -skip qtsensors \</span><br><span class="line"> -skip qtserialbus \</span><br><span class="line"> -skip qtserialport \</span><br><span class="line"> -skip qtspeech \</span><br><span class="line"> -skip qtsvg \</span><br><span class="line"> -skip qttools \</span><br><span class="line"> -skip qttranslations \</span><br><span class="line"> -skip qtvirtualkeyboard \</span><br><span class="line"> -skip qtwayland \</span><br><span class="line"> -skip qtwebchannel \</span><br><span class="line"> -skip qtwebengine \</span><br><span class="line"> -skip qtwebglplugin \</span><br><span class="line"> -skip qtwebsockets \</span><br><span class="line"> -skip qtwebview \</span><br><span class="line"> -skip qtwinextras \</span><br><span class="line"> -skip qtxmlpatterns \</span><br><span class="line"> -skip qtx11extras \</span><br><span class="line"> -no-iconv \</span><br><span class="line"> -no-harfbuzz \</span><br><span class="line"> -no-evdev</span><br></pre></td></tr></table></figure>

<h4 id="树莓派交叉环境编译"><a href="#树莓派交叉环境编译" class="headerlink" title="树莓派交叉环境编译"></a>树莓派交叉环境编译</h4><h5 id="配置交叉编译环境"><a href="#配置交叉编译环境" class="headerlink" title="配置交叉编译环境"></a>配置交叉编译环境</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">!/bin/bash</span></span><br><span class="line">mkdir -p ~/toolchain</span><br><span class="line">cd ~</span><br><span class="line">if [ $1 == "pi" ]; then</span><br><span class="line">	url="https://s3.amazonaws.com/RTI/Community/ports/toolchains/raspbian-toolchain-gcc-4.7.2-linux32.tar.gz"</span><br><span class="line">	name="$(pwd)/toolchain/raspbian-toolchain-gcc-4.7.2-linux32"</span><br><span class="line">		</span><br><span class="line">	if [ ! -d "$name" ]; then</span><br><span class="line">		wget $url</span><br><span class="line">		tar -zxvf raspbian-toolchain-gcc-4.7.2-linux32.tar.gz $name</span><br><span class="line">	fi</span><br><span class="line">	export PATH=$name/bin:$PATH</span><br><span class="line">	export CROSS_COMPILE=arm-raspbian-linux-gnueabi-</span><br><span class="line">	export CC="$CROSS_COMPILE"gcc</span><br><span class="line">	export CXX="$CROSS_COMPILE"g++	</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line">cd -</span><br></pre></td></tr></table></figure>

<h5 id="修改qmake-conf"><a href="#修改qmake-conf" class="headerlink" title="修改qmake.conf"></a>修改qmake.conf</h5><p>复制一份<strong>qt-everywhere-opensource-src-5.1.1/qtbase/mkspecs/arm-raspbian-linux-gnueabi-g++</strong></p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># qmake configuration for building with arm-linux-gnueabi-g++</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"></span><br><span class="line">MAKEFILE_GENERATOR      = UNIX</span><br><span class="line">CONFIG                 += incremental gdb_dwarf_index</span><br><span class="line">QMAKE_INCREMENTAL_STYLE = sublib</span><br><span class="line"></span><br><span class="line"><span class="keyword">include</span>(../common/linux.conf)</span><br><span class="line"><span class="keyword">include</span>(../common/gcc-base-unix.conf)</span><br><span class="line"><span class="keyword">include</span>(../common/g++-unix.conf)</span><br><span class="line"></span><br><span class="line">QT_QPA_DEFAULT_PLATFORM=linuxfb</span><br><span class="line"></span><br><span class="line"><span class="comment"># modifications to g++.conf</span></span><br><span class="line">QMAKE_CC                = arm-raspbian-linux-gnueabi-gcc</span><br><span class="line">QMAKE_CXX               = arm-raspbian-linux-gnueabi-g++</span><br><span class="line">QMAKE_LINK              = arm-raspbian-linux-gnueabi-g++</span><br><span class="line">QMAKE_LINK_SHLIB        = arm-raspbian-linux-gnueabi-g++</span><br><span class="line"></span><br><span class="line"><span class="comment"># modifications to linux.conf</span></span><br><span class="line">QMAKE_AR                = arm-raspbian-linux-gnueabi-ar cqs</span><br><span class="line">QMAKE_OBJCOPY           = arm-raspbian-linux-gnueabi-objcopy</span><br><span class="line">QMAKE_NM                = arm-raspbian-linux-gnueabi-nm -P</span><br><span class="line">QMAKE_STRIP             = arm-raspbian-linux-gnueabi-strip</span><br><span class="line">load(qt_config)</span><br></pre></td></tr></table></figure>

<h5 id="编写脚本"><a href="#编写脚本" class="headerlink" title="编写脚本"></a>编写脚本</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">!/bin/sh  </span></span><br><span class="line">tar xvf  ../arm-raspbian-linux-gnueabi-g++.tar.gz -C ./qtbase/mkspecs/</span><br><span class="line">./configure -prefix ../qt-output_pi/  \</span><br><span class="line">-opensource \</span><br><span class="line">-release \</span><br><span class="line">-confirm-license \</span><br><span class="line">-xplatform arm-raspbian-linux-gnueabi-g++  \</span><br><span class="line">-no-opengl \</span><br><span class="line">-no-pch \</span><br><span class="line">-shared \</span><br><span class="line">-no-iconv \</span><br><span class="line">-no-xcb \</span><br><span class="line">-nomake examples \</span><br><span class="line">-nomake tests \</span><br><span class="line">-nomake tools \</span><br></pre></td></tr></table></figure>

<h5 id="编译"><a href="#编译" class="headerlink" title="编译"></a>编译</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make -j4 &amp;&amp; make install</span><br></pre></td></tr></table></figure>


          
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/08/01/CMake编译QT/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/08/01/CMake编译QT/" class="post-title-link" itemprop="url">CMake编译QT</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-08-01 20:28:31" itemprop="dateCreated datePublished" datetime="2019-08-01T20:28:31+00:00">2019-08-01</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          
            <h3 id="使用CMake编译"><a href="#使用CMake编译" class="headerlink" title="使用CMake编译"></a>使用CMake编译</h3><h4 id="开始"><a href="#开始" class="headerlink" title="开始"></a>开始</h4><p>使用<code>find_package</code>找到QT库和文件，推荐方法是用<code>target_link_libraries</code> 命令，这个命令回自动的添加头文件目录，编译宏，地址无关代码和链接到qtmain这个库。</p>
<p>例子：</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">cmake_minimum_required</span>(VERSION <span class="number">3.1</span>.<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">project</span>(helloworld)</span><br><span class="line"></span><br><span class="line"><span class="keyword">set</span>(CMAKE_AUTOMOC <span class="keyword">ON</span>)</span><br><span class="line"><span class="keyword">set</span>(CMAKE_AUTORCC <span class="keyword">ON</span>)</span><br><span class="line"><span class="keyword">set</span>(CMAKE_AUTOUIC <span class="keyword">ON</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(CMAKE_VERSION <span class="keyword">VERSION_LESS</span> <span class="string">"3.7.0"</span>)</span><br><span class="line">    <span class="keyword">set</span>(CMAKE_INCLUDE_CURRENT_DIR <span class="keyword">ON</span>)</span><br><span class="line"><span class="keyword">endif</span>()</span><br><span class="line"></span><br><span class="line"><span class="keyword">find_package</span>(Qt5 COMPONENTS Widgets REQUIRED)</span><br><span class="line"></span><br><span class="line"><span class="keyword">add_executable</span>(helloworld</span><br><span class="line">    mainwindow.ui</span><br><span class="line">    mainwindow.cpp</span><br><span class="line">    main.cpp</span><br><span class="line">    resources.qrc</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="keyword">target_link_libraries</span>(helloworld Qt5::Widgets)</span><br></pre></td></tr></table></figure>

<p>为了<code>find_package</code>成功找到QT5，它必须在 CMAKE_PREFIX_PATH路径下，或者Qt5_DIR下必须有Qt5config.cmake文件。最简单的办法就是设置环境变量CMAKE_PREFIX_PATH为QT的按照目录。</p>
<p>同时CMAKE_AUTOMOC必须设置为ON。</p>
<p>详见<a href="https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html#automoc#" target="_blank" rel="noopener">https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html#automoc#</a>)</p>
<h4 id="导入模块"><a href="#导入模块" class="headerlink" title="导入模块"></a>导入模块</h4><p>引入模块可以像这样 Qt5<module>_LIBRARIES,比如在<code>target_link_libraries</code>. 实际的路径可以通过以下方式获取:</module></p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">find_package</span>(Qt5 COMPONENTS Core REQUIRED)</span><br><span class="line"></span><br><span class="line"><span class="keyword">get_target_property</span>(QtCore_location Qt5::Core LOCATION)</span><br></pre></td></tr></table></figure>

<p>很少需要知道完整的路径，每一个QT5模块的库，可以用Qt5::<module>方便的使用。</module></p>
<p>如果你的有自己的CMake文件，你必须设置debug或者release。例如</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">find_package</span>(Qt5 COMPONENTS Core REQUIRED)</span><br><span class="line"></span><br><span class="line"><span class="keyword">set</span>(CMAKE_CXX_FLAGS_COVERAGE <span class="string">"$&#123;CMAKE_CXX_FLAGS_RELEASE&#125; -fprofile-arcs -ftest-coverage"</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># set up a mapping so that the Release configuration for the Qt imported target is</span></span><br><span class="line"><span class="comment"># used in the COVERAGE CMake configuration.</span></span><br><span class="line"><span class="keyword">set_target_properties</span>(Qt5::Core PROPERTIES MAP_IMPORTED_CONFIG_COVERAGE <span class="string">"RELEASE"</span>)</span><br></pre></td></tr></table></figure>

<h4 id="导入插件"><a href="#导入插件" class="headerlink" title="导入插件"></a>导入插件</h4><p>插件同样支持导入， <a href="https://doc.qt.io/qt-5/qtnetwork-index.html" target="_blank" rel="noopener">Qt Network</a>, <a href="https://doc.qt.io/qt-5/qtsql-index.html" target="_blank" rel="noopener">Qt SQL</a>, <a href="https://doc.qt.io/qt-5/qtgui-index.html" target="_blank" rel="noopener">Qt GUI</a>, 和 <a href="https://doc.qt.io/qt-5/qtwidgets-index.html" target="_blank" rel="noopener">Qt Widgets</a> 模块都有关联的插件，他们都提供了插件列表，在Qt5<code>&lt;Module&gt;_PLUGINS</code>变量中。</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">foreach</span>(plugin <span class="variable">$&#123;Qt5Network_PLUGINS&#125;</span>)</span><br><span class="line">  <span class="keyword">get_target_property</span>(_loc <span class="variable">$&#123;plugin&#125;</span> LOCATION)</span><br><span class="line">  <span class="keyword">message</span>(<span class="string">"Plugin $&#123;plugin&#125; is at location $&#123;_loc&#125;"</span>)</span><br><span class="line"><span class="keyword">endforeach</span>()</span><br></pre></td></tr></table></figure>

<h3 id="Qt-Core"><a href="#Qt-Core" class="headerlink" title="Qt Core"></a>Qt Core</h3><p><a href="https://doc.qt.io/qt-5/qtcore-index.html" target="_blank" rel="noopener">https://doc.qt.io/qt-5/qtcore-index.html</a></p>
<p><strong>核心功能</strong></p>
<p>Qt将这些特性添加到C++中:</p>
<blockquote>
<p>1.一种非常强大的机制，用于无缝对象通信，称为信号和插槽<br>2.可查询和可设计的对象属性<br>3.组织的层次化和可查询的对象树<br>4.用保护指针(QPointer)的自然方式拥有对象所有权<br>5.跨库边界的动态转换</p>
</blockquote>
<p><strong>线程和并发编程</strong></p>
<blockquote>
<p>Qt以独立于平台的线程类的形式提供线程支持，线程安全的发布事件的方式，以及跨线程的信号槽连接。<br>多线程编程也是一种有用的范例，它可以在不冻结应用程序的用户界面的情况下执行耗时的操作。Qt页面中的线程支持包含在应用程序中实现线程的信息。额外的并发类由Qt并发模块提供。</p>
</blockquote>
<p><strong>输入/输出、资源和容器</strong></p>
<p>Qt提供了一种资源系统，用于组织应用程序文件和资产、一组容器和用于接收输入和打印输出的类:</p>
<blockquote>
<ol>
<li>容器类</li>
<li>序列化Qt数据类型</li>
<li>隐式共享</li>
<li>此外，Qt核心提供了一种独立于平台的机制，用于在应用程序的可执行文件中存储二进制文件。<br>Qt的资源系统</li>
</ol>
</blockquote>
<p><strong>额外的框架</strong></p>
<p>Qt Core还提供了Qt的一些关键框架:</p>
<blockquote>
<ol>
<li>动画框架</li>
<li>在Qt JSON支持</li>
<li>状态机框架</li>
<li>如何创建Qt插件</li>
<li>事件系统</li>
</ol>
</blockquote>
<h4 id="代码下载"><a href="#代码下载" class="headerlink" title="代码下载"></a>代码下载</h4><p><a href="http://download.qt.io/archive/qt/5.13/5.13.0/submodules/" target="_blank" rel="noopener">http://download.qt.io/archive/qt/5.13/5.13.0/submodules/</a></p>
<p><strong>QT和JS交互调用</strong></p>
<p><a href="https://blog.csdn.net/caoshangpa/article/details/51014690" target="_blank" rel="noopener">https://blog.csdn.net/caoshangpa/article/details/51014690</a></p>

          
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/17/V2X之MATLAB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/07/17/V2X之MATLAB/" class="post-title-link" itemprop="url">V2X之MATLAB</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-07-17 23:26:48" itemprop="dateCreated datePublished" datetime="2019-07-17T23:26:48+00:00">2019-07-17</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          
            
          
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/17/V2x之ASN.1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/07/17/V2x之ASN.1/" class="post-title-link" itemprop="url">C-V2X之ASN.1</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-07-17 09:53:00" itemprop="dateCreated datePublished" datetime="2019-07-17T09:53:00+00:00">2019-07-17</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>ASN.1 全称 Abstract Syntax Natation One. 是一个用来描述抽象类型抽象数据的语法. 类似于 XML, JSON 等, 主要用于编码数据以便于在网络中交换数据. </p>
<blockquote>
<p>在线解析工具：<a href="https://lapo.it/asn1js/" target="_blank" rel="noopener">https://lapo.it/asn1js/</a></p>
</blockquote>
<h3 id="ASN-1编码方式"><a href="#ASN-1编码方式" class="headerlink" title="ASN.1编码方式"></a>ASN.1编码方式</h3><h4 id="ASN-1-中定义四种类型"><a href="#ASN-1-中定义四种类型" class="headerlink" title="ASN.1 中定义四种类型"></a>ASN.1 中定义四种类型</h4><ul>
<li><p>简单类型 (Simple types) : 用于编码基本的数据类型. 如 整形,字符串,二进制数据等.</p>
</li>
<li><p>结构类型 (Structured types) : 用于编码复杂数据类型. 如, X509 证书中的公钥.</p>
</li>
<li><p>标记的类型 (Tagged types) : 用于编码从其他几种类型引申而来的类型.</p>
</li>
<li><p>其他类型 (Other types) : CHOICE 或 Any.</p></li></ul>
          <!--noindex-->
          
            <div class="post-button text-center">
              <a class="btn" href="/2019/07/17/V2x之ASN.1/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
      

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/07/09/CMake入门/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">
              
              <a href="/2019/07/09/CMake入门/" class="post-title-link" itemprop="url">CMake入门</a>
            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-07-09 13:15:39" itemprop="dateCreated datePublished" datetime="2019-07-09T13:15:39+00:00">2019-07-09</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          
            <h3 id="CMake管理工程"><a href="#CMake管理工程" class="headerlink" title="CMake管理工程"></a>CMake管理工程</h3><p>在Linux平台下使用CMake生成Makefile并编译的流程如下：</p>
<ol>
<li>编写CMake配置文件CMakeLists.txt</li>
<li>执行命令cmake PATH生成<strong>Makefile</strong>，PATH是CMakeLists.txt所在的目录。</li>
<li>使用make命令进行编译。</li>
</ol>
<p>简单讲就是<strong>CMake是自动生成Makefile文件的工具</strong></p>
<h4 id="安装CMake"><a href="#安装CMake" class="headerlink" title="安装CMake"></a>安装CMake</h4><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install cmake</span><br></pre></td></tr></table></figure>

<h4 id="创建CMakeLists-txt-骨架"><a href="#创建CMakeLists-txt-骨架" class="headerlink" title="创建CMakeLists.txt 骨架"></a>创建CMakeLists.txt 骨架</h4><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># CMake 最低版本号要求 不写会有警告</span></span><br><span class="line"><span class="keyword">cmake_minimum_required</span> (VERSION <span class="number">2.8</span>)</span><br><span class="line"><span class="comment"># 项目信息</span></span><br><span class="line"><span class="keyword">project</span> (Demo1)</span><br><span class="line"><span class="comment"># 指定生成目标</span></span><br><span class="line"><span class="keyword">add_executable</span>(Demo main.cpp)</span><br></pre></td></tr></table></figure>

<h4 id="CMakeLists-txt中的编写方法"><a href="#CMakeLists-txt中的编写方法" class="headerlink" title="CMakeLists.txt中的编写方法"></a>CMakeLists.txt中的编写方法</h4><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">project</span>(Demo1) <span class="comment"># App的名称，需要修改⭐️</span></span><br><span class="line"><span class="keyword">cmake_minimum_required</span>(VERSION <span class="number">2.8</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#加载自定义模块</span></span><br><span class="line"><span class="keyword">set</span>(CMAKE_MODULE_PATH <span class="variable">$&#123;CMAKE_MODULE_PATH&#125;</span> <span class="string">"$&#123;PROJECT_SOURCE_DIR&#125;/cmake"</span>)</span><br><span class="line"><span class="comment">#设置库文件路径</span></span><br><span class="line"><span class="keyword">set</span>(LIBRARY_OUTPUT_PATH <span class="variable">$&#123;PROJECT_BINARY_DIR&#125;</span>/lib)</span><br><span class="line"><span class="comment">#设置可执行程序路径</span></span><br><span class="line"><span class="keyword">set</span>(EXECUTABLE_OUTPUT_PATH <span class="variable">$&#123;PROJECT_BINARY_DIR&#125;</span>/bin)</span><br><span class="line"><span class="comment">#设置子目录</span></span><br><span class="line"><span class="keyword">set</span>(SUB_DIR_LIST <span class="string">"Thread"</span> <span class="string">"Util"</span>) <span class="comment">#需要修改⭐️</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#安装目录</span></span><br><span class="line"><span class="keyword">set</span>(INSTALL_PATH_LIB lib)</span><br><span class="line"><span class="keyword">set</span>(INSTALL_PATH_INCLUDE <span class="keyword">include</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">foreach</span>(SUB_DIR <span class="variable">$&#123;SUB_DIR_LIST&#125;</span>)</span><br><span class="line">    <span class="comment">#遍历源文件</span></span><br><span class="line">    <span class="keyword">aux_source_directory</span>(src/<span class="variable">$&#123;SUB_DIR&#125;</span> SRC_LIST)</span><br><span class="line">    <span class="comment">#安装头文件至系统目录</span></span><br><span class="line">    <span class="keyword">install</span>(DIRECTORY src/<span class="variable">$&#123;SUB_DIR&#125;</span> DESTINATION <span class="variable">$&#123;INSTALL_PATH_INCLUDE&#125;</span> FILES_MATCHING PATTERN <span class="string">"*.h"</span>)</span><br><span class="line"><span class="keyword">endforeach</span>()</span><br><span class="line"></span><br><span class="line"><span class="comment">#或者，搜集文件，并把文件列表赋给ToolKit_src_list</span></span><br><span class="line"><span class="keyword">file</span>(GLOB ToolKit_src_list <span class="variable">$&#123;ToolKit_Root&#125;</span>/*/*.cpp <span class="variable">$&#123;ToolKit_Root&#125;</span>/*/*.h <span class="variable">$&#123;ToolKit_Root&#125;</span>/*/*.c)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">set</span>(LINK_LIB_LIST)</span><br><span class="line"></span><br><span class="line"><span class="keyword">set</span>(ENABLE_OPENSSL <span class="keyword">true</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#查找openssl是否安装   需要修改⭐️</span></span><br><span class="line"><span class="keyword">find_package</span>(OpenSSL QUIET) </span><br><span class="line"><span class="keyword">if</span>(OPENSSL_FOUND <span class="keyword">AND</span> ENABLE_OPENSSL)</span><br><span class="line">    <span class="keyword">message</span>(STATUS <span class="string">"找到openssl库:\"$&#123;OPENSSL_INCLUDE_DIR&#125;\",ENABLE_OPENSSL宏已打开"</span>)</span><br><span class="line">    <span class="keyword">include_directories</span>(<span class="variable">$&#123;OPENSSL_INCLUDE_DIR&#125;</span>)</span><br><span class="line">    <span class="keyword">add_definitions</span>(-DENABLE_OPENSSL) <span class="comment"># 定义宏</span></span><br><span class="line">    <span class="keyword">list</span>(APPEND  LINK_LIB_LIST <span class="variable">$&#123;OPENSSL_LIBRARIES&#125;</span>)</span><br><span class="line"><span class="keyword">endif</span>()</span><br><span class="line"></span><br><span class="line"><span class="comment">#打印库文件</span></span><br><span class="line"><span class="keyword">message</span>(STATUS <span class="string">"将链接依赖库:$&#123;LINK_LIB_LIST&#125;"</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#引用头文件路径</span></span><br><span class="line"><span class="keyword">include_directories</span>(<span class="variable">$&#123;PROJECT_SOURCE_DIR&#125;</span>/src)</span><br><span class="line"><span class="comment">#使能c++11</span></span><br><span class="line"><span class="keyword">add_compile_options</span>(-std=c++<span class="number">11</span>)<span class="comment"># 需要修改⭐️</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 修改其他编译选项</span></span><br><span class="line"><span class="keyword">add_compile_options</span>(-Wno-deprecated-declarations)</span><br><span class="line"><span class="keyword">add_compile_options</span>(-Wno-predefined-identifier-outside-<span class="keyword">function</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#编译动态库</span></span><br><span class="line"><span class="keyword">add_library</span>(<span class="variable">$&#123;CMAKE_PROJECT_NAME&#125;</span>_shared SHARED <span class="variable">$&#123;SRC_LIST&#125;</span>)</span><br><span class="line"><span class="keyword">target_link_libraries</span>(<span class="variable">$&#123;CMAKE_PROJECT_NAME&#125;</span>_shared <span class="variable">$&#123;LINK_LIB_LIST&#125;</span>)</span><br><span class="line"><span class="keyword">set_target_properties</span>(<span class="variable">$&#123;CMAKE_PROJECT_NAME&#125;</span>_shared PROPERTIES OUTPUT_NAME <span class="string">"$&#123;CMAKE_PROJECT_NAME&#125;"</span>)</span><br><span class="line"><span class="keyword">install</span>(TARGETS <span class="variable">$&#123;CMAKE_PROJECT_NAME&#125;</span>_shared  ARCHIVE DESTINATION <span class="variable">$&#123;INSTALL_PATH_LIB&#125;</span> LIBRARY DESTINATION <span class="variable">$&#123;INSTALL_PATH_LIB&#125;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#编译静态库</span></span><br><span class="line"><span class="keyword">add_library</span>(<span class="variable">$&#123;CMAKE_PROJECT_NAME&#125;</span>_static STATIC <span class="variable">$&#123;SRC_LIST&#125;</span>)</span><br><span class="line"><span class="keyword">set_target_properties</span>(<span class="variable">$&#123;CMAKE_PROJECT_NAME&#125;</span>_static PROPERTIES OUTPUT_NAME <span class="string">"$&#123;CMAKE_PROJECT_NAME&#125;"</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#安装静态库至系统目录</span></span><br><span class="line"><span class="keyword">install</span>(TARGETS <span class="variable">$&#123;CMAKE_PROJECT_NAME&#125;</span>_static ARCHIVE DESTINATION <span class="variable">$&#123;INSTALL_PATH_LIB&#125;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#测试程序的目录中也有CMakeLists.txt</span></span><br><span class="line"><span class="keyword">add_subdirectory</span>(tests)</span><br></pre></td></tr></table></figure>

<h4 id="测试程序的CMakeList编写方法"><a href="#测试程序的CMakeList编写方法" class="headerlink" title="测试程序的CMakeList编写方法"></a>测试程序的CMakeList编写方法</h4><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 执行cp命令</span></span><br><span class="line"><span class="keyword">execute_process</span>(<span class="keyword">COMMAND</span> cp <span class="variable">$&#123;CMAKE_CURRENT_SOURCE_DIR&#125;</span>/ssl.p12 <span class="variable">$&#123;EXECUTABLE_OUTPUT_PATH&#125;</span>/)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 当前目录加入TEST_SRC_LIST</span></span><br><span class="line"><span class="keyword">aux_source_directory</span>(. TEST_SRC_LIST) </span><br><span class="line"><span class="comment"># 遍历TEST_SRC_LIST</span></span><br><span class="line"><span class="keyword">foreach</span>(TEST_SRC <span class="variable">$&#123;TEST_SRC_LIST&#125;</span>)</span><br><span class="line">		<span class="comment"># 去掉后缀</span></span><br><span class="line">    <span class="keyword">STRING</span>(REGEX REPLACE <span class="string">"^\\./|\\.c[a-zA-Z0-9_]*$"</span> <span class="string">""</span> TEST_EXE_NAME <span class="variable">$&#123;TEST_SRC&#125;</span>)</span><br><span class="line">    <span class="keyword">message</span>(STATUS <span class="string">"添加测试程序:$&#123;TEST_EXE_NAME&#125;"</span>)</span><br><span class="line">    <span class="comment"># 每个cpp作为一个可执行文件</span></span><br><span class="line">    <span class="keyword">add_executable</span>(<span class="variable">$&#123;TEST_EXE_NAME&#125;</span> <span class="variable">$&#123;TEST_SRC&#125;</span>)</span><br><span class="line">		<span class="comment"># 连接动态库</span></span><br><span class="line">    <span class="keyword">target_link_libraries</span>(<span class="variable">$&#123;TEST_EXE_NAME&#125;</span> <span class="variable">$&#123;CMAKE_PROJECT_NAME&#125;</span>_shared <span class="variable">$&#123;LINK_LIB_LIST&#125;</span> pthread)</span><br><span class="line"></span><br><span class="line"><span class="keyword">endforeach</span>(TEST_SRC <span class="variable">$&#123;TEST_SRC_LIST&#125;</span>)</span><br></pre></td></tr></table></figure>

<h5 id="cmake-find-package的基本原理"><a href="#cmake-find-package的基本原理" class="headerlink" title="cmake find_package的基本原理"></a>cmake find_package的基本原理</h5><p>比如说，我们需要一个第三方库 curl，那么我们的 CMakeLists.txt 需要指定头文件目录，和库文件，类似</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">include_directiories(/usr/<span class="keyword">include</span>/curl)</span><br><span class="line"><span class="keyword">target_link_libraries</span>(myprogram path/curl.so)</span><br></pre></td></tr></table></figure>

<p>如果借助于cmake提供的finder会怎么样呢？使用cmake的Modules目录下的FindCURL.cmake，相应的CMakeList.txt 文件：</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">find_package</span>(CURL REQUIRED)</span><br><span class="line"><span class="keyword">include_directories</span>(<span class="variable">$&#123;CURL_INCLUDE_DIR&#125;</span>)</span><br><span class="line"><span class="keyword">target_link_libraries</span>(curltest <span class="variable">$&#123;CURL_LIBRARY&#125;</span>)</span><br></pre></td></tr></table></figure>

<p>那么cmake是如何查找的呢？</p>
<blockquote>
<p>find_package()命令首先会在模块路径中寻找Find.cmake，这是查找库的一个典型方式。具体查找路径依次为CMake：变量{CMAKE_MODULE_PATH}中的所有目录。如果没有，然后再查看它自己的模块目录/share/cmake-x.y/Modules/（$CMAKE_ROOT的具体值可以通过CMake中message命令输出）。这称为模块模式。</p>
</blockquote>
<p>为了能支持各种常见的库和包，CMake自带了很多模块。可以通过命令 cmake –help-module-list （输入cmake –help，然后双击Tab会有命令提示）得到你的CMake支持的模块的列表： 直接查看模块路径。比如Ubuntu linux上，模块的路径是 ls /usr/share/cmake/Modules/：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">ll -th /usr/share/cmake-<span class="number">3.5</span>/Modules/</span><br><span class="line">......</span><br><span class="line">-rw-r--r--  <span class="number">1</span> root root  <span class="number">76</span>K Sep <span class="number">27</span>  <span class="number">2016</span> FindBoost.cmake</span><br><span class="line">-rw-r--r--  <span class="number">1</span> root root <span class="number">2.7</span>K Mar <span class="number">24</span>  <span class="number">2016</span> FindCoin3D.cmake</span><br><span class="line">-rw-r--r--  <span class="number">1</span> root root  <span class="number">77</span>K Mar <span class="number">24</span>  <span class="number">2016</span> FindCUDA.cmake</span><br><span class="line">-rw-r--r--  <span class="number">1</span> root root <span class="number">3.1</span>K Mar <span class="number">24</span>  <span class="number">2016</span> FindCups.cmake</span><br><span class="line">-rw-r--r--  <span class="number">1</span> root root <span class="number">2.4</span>K Mar <span class="number">24</span>  <span class="number">2016</span> FindCURL.cmake</span><br><span class="line">........</span><br></pre></td></tr></table></figure>

<p>让我们以bzip2库为例。CMake中有个 FindBZip2.cmake 模块。只要使用 find_package(BZip2) 调用这个模块，cmake会自动给一些变量赋值，然后就可以在CMake脚本中使用它们了。变量的列表可以查看cmake模块文件，或者使用命令:</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">root@xy:~/cmake_practice/cmake_build/build_demo10<span class="comment"># cmake --help-module FindBZip2</span></span><br><span class="line">FindBZip2</span><br><span class="line"><span class="keyword">Try</span> to find BZip2</span><br><span class="line"></span><br><span class="line">Once done this will define</span><br><span class="line">::</span><br><span class="line">BZIP2_FOUND - system has BZip2</span><br><span class="line">BZIP2_INCLUDE_DIR - the BZip2 include directory</span><br><span class="line">BZIP2_LIBRARIES - Link these to use BZip2</span><br><span class="line">BZIP2_NEED_PREFIX - this is set <span class="keyword">if</span> the functions are prefixed with BZ2_</span><br><span class="line">BZIP2_VERSION_STRING - the version of BZip2 found (since CMake <span class="number">2.8</span>.<span class="number">8</span>)</span><br></pre></td></tr></table></figure>

<h5 id="Filesystem"><a href="#Filesystem" class="headerlink" title="Filesystem"></a>Filesystem</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">file(GLOB &lt;variable&gt;</span><br><span class="line">     [LIST_DIRECTORIES true|false] [RELATIVE &lt;path&gt;] [CONFIGURE_DEPENDS]</span><br><span class="line">     [&lt;globbing-expressions&gt;...])</span><br><span class="line">file(GLOB_RECURSE &lt;variable&gt; [FOLLOW_SYMLINKS]</span><br><span class="line">     [LIST_DIRECTORIES true|false] [RELATIVE &lt;path&gt;] [CONFIGURE_DEPENDS]</span><br><span class="line">     [&lt;globbing-expressions&gt;...])</span><br></pre></td></tr></table></figure>

<p>产生一个匹配 <code>&lt;globbing-expressions&gt;</code> 的文件列表并将它存储到变量 <code>&lt;variable&gt;</code> 中。文件名替代表达式和正则表达式相似，但更简单。如果 <code>RELATIVE</code> 标志位被设定，将返回指定路径的相对路径。结果将按字典顺序排序。</p>
<p>如果 <code>CONFIGURE_DEPENDS</code> 标志位被指定，CMake 将在编译时给主构建系统添加逻辑来检查目标，以重新运行 <code>GLOB</code> 标志的命令。如果任何输出被改变，CMake都将重新生成这个构建系统。</p>
<blockquote>
<p>注意：我们不推荐使用 GLOB 来从源文件树收集源文件列表。如果当源文件添加或删除时没有 CMakeLists.txt 文件被修改，那么在 CMake 重新生成时并不会识别出它们。<code>CONFIGURE_DEPENDS</code> 标志位可能不会再所有生成器上可靠的工作，如果一个新的生成器在以后被添加，并不会被支持。如果项目使用它将会被卡主。即使 <code>CONFIGURE_DEPENDS</code> 可靠的工作，在每个重新构建的过程中做检查也十分浪费性能。</p>
</blockquote>
<h4 id="交叉编译配置"><a href="#交叉编译配置" class="headerlink" title="交叉编译配置"></a>交叉编译配置</h4><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">SET</span>(TOOLSCHAIN_PATH /home/zero/sdk/gcc-<span class="number">4.6</span>.<span class="number">2</span>-glibc-<span class="number">2.13</span>-linaro-multilib-<span class="number">2011.12</span>/fsl-linaro-toolchain/)</span><br><span class="line"><span class="keyword">set</span>(TOOLCHAIN_HOST <span class="string">"$&#123;TOOLSCHAIN_PATH&#125;bin/arm-none-linux-gnueabi"</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">set</span>(TOOLCHAIN_CC <span class="string">"$&#123;TOOLCHAIN_HOST&#125;-gcc"</span>)</span><br><span class="line"><span class="keyword">set</span>(TOOLCHAIN_CXX <span class="string">"$&#123;TOOLCHAIN_HOST&#125;-g++"</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># Define the compiler</span></span><br><span class="line"><span class="keyword">set</span>(CMAKE_C_COMPILER <span class="variable">$&#123;TOOLCHAIN_CC&#125;</span>)</span><br><span class="line"><span class="keyword">set</span>(CMAKE_CXX_COMPILER <span class="variable">$&#123;TOOLCHAIN_CXX&#125;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#告诉cmake是进行交叉编译</span></span><br><span class="line"><span class="keyword">set</span>(CMAKE_CROSSCOMPILING <span class="keyword">TRUE</span>)</span><br></pre></td></tr></table></figure>

<h4 id="编译传参数"><a href="#编译传参数" class="headerlink" title="编译传参数"></a>编译传参数</h4><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">CMake <span class="keyword">option</span></span><br><span class="line">使用场景 : 编译脚本传递参数 -&gt; CMake脚本接收<span class="keyword">option</span> -&gt; 源代码宏</span><br><span class="line"></span><br><span class="line">编译脚本传入参数</span><br><span class="line">传入一个cmake <span class="keyword">option</span> TEST_DEBUG</span><br><span class="line"></span><br><span class="line"><span class="comment">#!/bin/sh</span></span><br><span class="line"></span><br><span class="line">cmake -DTEST_DEBUG=<span class="keyword">ON</span> .</span><br><span class="line">cmake --build .</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">CMake脚本接收<span class="keyword">option</span></span><br><span class="line">cmake 脚本定义TEST_DEBUG 默认关闭<span class="keyword">OFF</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">project</span>(<span class="keyword">test</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">option</span>(TEST_DEBUG <span class="string">"option for debug"</span> <span class="keyword">OFF</span>)</span><br><span class="line"><span class="keyword">if</span> (TEST_DEBUG)</span><br><span class="line"><span class="keyword">add_definitions</span>(-DTEST_DEBUG)</span><br><span class="line"><span class="keyword">endif</span>()</span><br><span class="line">...</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">源代码宏 <span class="keyword">test</span>.c</span><br><span class="line"></span><br><span class="line"><span class="comment">#include "test.h"</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#ifdef TEST_DEBUG</span></span><br><span class="line">...</span><br><span class="line"><span class="comment">#endif</span></span><br></pre></td></tr></table></figure>


          
        
      
    </div>

    
    
    
      <footer class="post-footer">
          <div class="post-eof"></div>
        
      </footer>
  </div>
  
  
  
  </article>

    
  </section>

  
  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/">5</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>


          </div>
          

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      <div class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">

          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">XuQi</p>
  <div class="site-description motion-element" itemprop="description"></div>
</div>
  <nav class="site-state motion-element">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">44</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">30</span>
        <span class="site-state-item-name">标签</span>
        
      </div>
    
  </nav>



        </div>
      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">XuQi</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.9.0</div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> v7.3.0</div>

        








        
      </div>
    </footer>
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
      </div>

    

  </div>

  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

<script src="/js/utils.js?v=7.3.0"></script>
  <script src="/js/motion.js?v=7.3.0"></script>


  <script src="/js/schemes/muse.js?v=7.3.0"></script>


<script src="/js/next-boot.js?v=7.3.0"></script>




  




























  

  

  


  
</body>
</html>
